package com.jiang.daily.Q2296;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/02/27 17:58
 */
class TextEditor {
    private StringBuilder content;
    private int cur;

    public TextEditor() {
        content = new StringBuilder();
        cur = 0;
    }

    public void addText(String text) {
        content.insert(cur, text);
        cur += text.length();
    }

    public int deleteText(int k) {
        int cnt = Math.min(cur, k);
        int start = cur - cnt;
        content.delete(start, cur);
        cur = start;
        return cnt;
    }

    public String cursorLeft(int k) {
        cur = Math.max(0, cur - k);
        return content.substring(Math.max(0, cur - 10), cur);
    }

    public String cursorRight(int k) {
        cur = Math.min(content.length(), cur + k);
        return content.substring(Math.max(0, cur - 10), cur);
    }
}

